#include <iostream>
#include <fstream>

#include "KnnClassifier.h"
#include "fuzzyclassifier.h"

using namespace fc;
using namespace std;

void test ( Classifier& classifier, string file_path );

int main ( int argc, char **argv )
{
    for(int fs = 2; fs < 15; ++fs)
    {
        cout << "FS == " << fs << endl;
        FuzzyClassifier classifier(fs);
//         KnnClassifier classifier;
        test ( classifier, "/home/lukasz/Dokumenty/iris.txt");
    }
    cin.get();
    return 0;
}

void test ( Classifier & classifier, string file_path )
{
    ifstream f ( file_path.c_str() );
    if ( !f ) return;
    int attrs;
    int size;
    f >> size >> attrs;
    vector<Example> examples;
    vector<Example> testData;
    for ( int i = 0; i < size; i++ )
    {
        Example ex;
        float value;
        for ( int j = 0; j < attrs; j++ )
        {
            f >> value;
            ex.antacedent.push_back ( value );
        }
        int cl;
        f >> cl;
        ex.consequent = cl;
        if ( i % 5 == 0 )
            examples.push_back ( ex );
        else
            testData.push_back ( ex );
    }
    f.close();
    classifier.setTrainingData ( examples, attrs );

    int all = testData.size();
    int rights = 0;
    int unknown = 0;
    for ( vector<Example>::const_iterator it = testData.begin(); 
         it != testData.end(); ++it )
    {
        Result result = classifier.classify ( it->antacedent );
        if ( result.resultClass == it->consequent )
            rights++;
        if( result.weight == 0)
            unknown++;
    }

    cout << rights << "/" << all << " sklasyfikowano poprawnie. Jest to " 
        << ( double ) rights * 100 / ( double ) all << "%" << endl;
    cout << unknown << "/" << all << " nie sklasyfikowano w ogole. Jest to " 
        << ( double ) unknown * 100 / ( double ) all << "%" << endl;
}
